<template>
  <el-dialog
    :title="!dataForm.numberre ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
<!--    <el-form-item label="部门编号" prop="deptId">-->
<!--      <el-input v-model="dataForm.deptId" placeholder="部门id"></el-input>-->
<!--    </el-form-item>-->
      <el-form-item label="部门编号" prop="deptId">
        <el-select v-model="dataForm.deptId" placeholder="部门id">
          <el-option key="5" label="ABS" value="5"></el-option>
          <el-option key="6" label="PS" value="6"></el-option>
          <el-option key="7" label="PTA" value="7"></el-option>
          <el-option key="8" label="PIA" value="8"></el-option>
          <el-option key="9" label="PVC(均一粉)" value="9"></el-option>
          <el-option key="10" label="PVC(乳化粉)" value="10"></el-option>
          <el-option key="11" label="PP" value="11"></el-option>
          <el-option key="12" label="EVA" value="12"></el-option>
          <el-option key="13" label="SAP" value="13"></el-option>
          <el-option key="15" label="BPA" value="15"></el-option>
          <el-option key="16" label="DOTP" value="16"></el-option>
          <el-option key="17" label="AE" value="17"></el-option>
        </el-select>
      </el-form-item>
    <el-form-item label="车厂" prop="carshop">
      <el-input v-model="dataForm.carshop" placeholder="车厂"></el-input>
    </el-form-item>
    <el-form-item label="驻厂人员" prop="idrp">
      <el-input v-model="dataForm.idrp" placeholder="驻厂人员"></el-input>
    </el-form-item>
    <el-form-item label="司机身份证号" prop="idcard">
      <el-input v-model="dataForm.idcard" placeholder="司机身份证号"></el-input>
    </el-form-item>
    <el-form-item label="车型" prop="lineorder">
<!--      <el-input v-model="dataForm.lineorder" placeholder="排队次序"></el-input>-->
      <el-select v-model="dataForm.lineorder" placeholder="车型">
        <el-option key="2" label="厢式X" value="2"></el-option>
        <el-option key="1" label="平板P" value="1"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="急单" prop="urgency">
      <el-select v-model="dataForm.urgency" placeholder="急单">
        <el-option key="0" label="正常" value="0"></el-option>
        <el-option key="1" label="急单" value="1"></el-option>
      </el-select>
<!--      <el-input v-model="dataForm.urgency" placeholder="急单（是1否0）"></el-input>-->
    </el-form-item>
<!--      <el-form-item label="排队号码" prop="queuePosition">-->
<!--        <el-input v-model="dataForm.queuePosition" placeholder="排队号码"></el-input>-->
<!--      </el-form-item>-->
    <el-form-item label="报道时间" prop="registertime">
      <el-input v-model="dataForm.registertime" placeholder="报道时间"></el-input>
    </el-form-item>
    <el-form-item label="报道状态" prop="registerstate">
<!--      <el-input v-model="dataForm.registerstate" placeholder="报道状态"></el-input>-->
      <el-select v-model="dataForm.registerstate" placeholder="报道状态">
        <el-option key="1" label="已叫号" value="1"></el-option>
        <el-option key="2" label="排队中" value="2"></el-option>
        <el-option key="3" label="已报到" value="3"></el-option>
        <el-option key="4" label="未报到" value="4"></el-option>
        <el-option key="5" label="已出厂" value="5"></el-option>
<!--        已叫号状态为第一次序1，排队中状态为第二次序2，已报到为第三次序3，未报到为第四次序4，已出厂为第5次序5-->
      </el-select>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          numberre: 0,
          deptId: '',
          carshop: '',
          idrp: '',
          idcard: '',
          lineorder: '',
          urgency: '',
          registertime: '',
          registerstate: ''
          // queuePosition: ''
        },
        dataRule: {
          deptId: [
            { required: true, message: '部门编号不能为空', trigger: 'blur' }
          ],
          idcard: [
            { required: true, message: '司机身份证号不能为空', trigger: 'blur' }
          ],
          urgency: [
            { required: true, message: '急单（是1否0）不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.numberre = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.numberre) {
            this.$http({
              url: this.$http.adornUrl(`/PCguanli/line/info/${this.dataForm.numberre}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.deptId = data.line.deptId
                this.dataForm.carshop = data.line.carshop
                this.dataForm.idrp = data.line.idrp
                this.dataForm.idcard = data.line.idcard
                this.dataForm.lineorder = data.line.lineorder
                this.dataForm.urgency = data.line.urgency
                this.dataForm.registertime = data.line.registertime
                this.dataForm.registerstate = data.line.registerstate
                // this.dataForm.queuePosition = data.line.queuePosition
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/PCguanli/line/${!this.dataForm.numberre ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'numberre': this.dataForm.numberre || undefined,
                'deptId': this.dataForm.deptId,
                'carshop': this.dataForm.carshop,
                'idrp': this.dataForm.idrp,
                'idcard': this.dataForm.idcard,
                'lineorder': this.dataForm.lineorder,
                'urgency': this.dataForm.urgency,
                'registertime': this.dataForm.registertime,
                'registerstate': this.dataForm.registerstate
                // 'queuePosition': this.dataForm.queuePosition
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
